var e = require;
var t = module;
var o = exports;
var n;
Object.defineProperty(o, "__esModule", {value: !0}), (o.InterstitialType = void 0);
var r,
    s = e("SDK"),
    c = e("VivoAd"),
    l = e("AdUtils"),
    d = e("NativeAdComponent"),
    u = cc._decorator,
    p = u.ccclass;
u.property,
    (function (e) {
        (e[(e.INTERSTITIAL_GAME_OVER = 0)] = "INTERSTITIAL_GAME_OVER"),
            (e[(e.INTERSTITIAL_GAME_STARE = 1)] = "INTERSTITIAL_GAME_STARE"),
            (e[(e.INTERSTITIAL_GAME_PAUSE = 2)] = "INTERSTITIAL_GAME_PAUSE"),
            (e[(e.INTERSTITIAL_GAME_LOADING = 3)] = "INTERSTITIAL_GAME_LOADING");
    })((r = o.InterstitialType || (o.InterstitialType = {})));
var h = (function (e) {
    function t() {
        var t = (null !== e && e.apply(this, arguments)) || this;
        return (t._insetList = []), t;
    }
    return (
        __extends(t, e),
        (t.prototype.init = function (e) {
            (this._config = e), l.default.instance.log("创建Interstitial广告");
        }),
        (t.prototype.showBanner = function (e) {
            if (e) {
                if (1 != e.enable) return;
                var t = e.type,
                    o = d.NativeType.BANNER;
                1 == t ? (o = d.NativeType.BANNER_BUTTON) : 2 == t && (o = d.NativeType.BANNER_LITTLE_BUTTON),
                    c.default.Instance.getBanner().showBanner(o, e.top, e.x, e.y);
            }
        }),
        (t.prototype.showInterstitial = function (e) {
            void 0 === e && (e = r.INTERSTITIAL_GAME_OVER);
            var t = this;
            if (null != this._config) {
                var o = JSON.parse(this._config.inser_ad_node);
                if (1 == this._config.enable)
                    if (null == o || o.length <= 0)
                        l.default.instance.log("---------showInterstitial 未配置广告节点adNodeList为空");
                    else {
                        var n = o[e];
                        if (null != n) {
                            if (n && 1 != n.enable) this.showBanner(n.banner);
                            else {
                                var i = c.default.Instance.getVivoNativeData();
                                if (null == i || !i.isReady())
                                    return (
                                        l.default.instance.log("---------showInterstitial 广告数据不存在-----"),
                                        void this.showBanner(n.banner)
                                    );
                                var a = cc.director.getScene().children[0],
                                    s = a.getChildByName("insertAd");
                                s && s.removeFromParent(),
                                    l.default.instance.delayShow(function () {
                                        t.show(a, i, n);
                                    });
                            }
                        } else l.default.instance.log("---------showInterstitial 节点未配置广告nodeId：" + e);
                    }
            }
        }),
        (t.prototype.show = function (e, t, o) {
            var n = this,
                i = this,
                a = function () {
                    c.default.Instance.creatorNativeData(),
                        s.default.Instance.reportLog(s.NodeAction.NATIVE_CLICK, "原生插屏点击");
                },
                r = function () {
                    c.default.Instance.hideBanner(),
                        c.default.Instance.creatorNativeData(),
                        s.default.Instance.reportLog(s.NodeAction.NATIVE_SHOW, "原生插屏展示");
                },
                u = function () {
                    o && o.show_banner && o.show_banner > 0 && n.showBanner(o.banner),
                        i.cleanInset(),
                        s.default.Instance.reportLog(s.NodeAction.NATIVE_CLOSE, "原生插屏关闭");
                };
            l.default.instance.loadPrefabs("sdk/res/prefabs/NativeInsertAd", function (o) {
                var n = cc.instantiate(o),
                    s = n.addComponent(d.default);
                s.initData(t),
                    s.listionCall(r, a, u),
                    s.showAd(d.NativeType.INSET, i._config),
                    e.addChild(n, 1e3, "insert"),
                    i.cacheInset(n);
            });
        }),
        (t.prototype.cleanInset = function () {
            this._insetList &&
                this._insetList.length > 0 &&
                (this._insetList.forEach(function (e) {
                    e && (e.removeFromParent(), e.destroy());
                }),
                (this._insetList = []));
        }),
        (t.prototype.cacheInset = function (e) {
            this.cleanInset(), this._insetList && this._insetList.push(e);
        }),
        __decorate([p], t)
    );
})(cc.Component);
o.default = h;
